package com.sjtu.rental.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sjtu.rental.entity.House;
import com.sjtu.rental.form.SearchForm;
import com.sjtu.rental.services.HouseService;

/**
 * 首页
 * 
 * @author Jessdy
 * 
 */
@Controller
@RequestMapping("/")
public class IndexController {
	
	@Autowired
	private HouseService houseService;

	/**
	 * 首页方法
	 * 
	 * @return 首页页面
	 */
	@RequestMapping
	public String init(Model model) {
		model.addAttribute("searchForm", new SearchForm());
		
		//十万火急房源：租金降序
		List<House> priceHouses = houseService.getHouseByPrice();
		model.addAttribute("priceHouses", priceHouses);
		//最新个人房源
		List<House> lastHouses = houseService.getHouseByTime();
		model.addAttribute("lastHouses", lastHouses);
		//租金指导价
		//最近成交
		List<House> dealHouses = houseService.getDealHouses();
		model.addAttribute("dealHouses", dealHouses);
		//热门预约房源
		List<House> hotHouses = houseService.getHotHouses();
		model.addAttribute("hotHouses", hotHouses);
		//今天发布的房源数
		int todayCount = houseService.getTodayHouseCount();
		model.addAttribute("todayCount", todayCount);
		return "index";
	}
}
